var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports", "./local-service", "maishu-chitu-admin/static", "./account-service", "./member-service"], function (require, exports, local_service_1, static_1, account_service_1, member_service_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    let localService = new local_service_1.LocalService(err => static_1.errorHandle(err));
    let memberService = new member_service_1.MemberService(err => static_1.errorHandle(err));
    let userDataSource = new static_1.PageDataSource({
        select: (args) => __awaiter(void 0, void 0, void 0, function* () {
            let r = yield memberService.members(args);
            let userIds = r.dataItems.map(o => o.Id);
            let accountService = new account_service_1.AccountService(err => static_1.errorHandle(err));
            let accounts = yield accountService.accountBalances(userIds);
            for (let i = 0; i < r.dataItems.length; i++) {
                let account = accounts.filter(o => o.Id == r.dataItems[i].Id)[0];
                if (account == null)
                    continue;
                r.dataItems[i].Balance = account.Balance;
            }
            return r;
        }),
        search: {
            placeholder: "请输入会员手机",
            execute() {
                return __awaiter(this, void 0, void 0, function* () {
                    return { dataItems: [], totalRowCount: 0 };
                });
            }
        }
    });
    exports.dataSources = {
        user: userDataSource
    };
});
